![]() ![]() ![]() ![]() | Table of Contents |
This lesson picks apart a simple Java program that has a graphical UI, explaining:
- the classes the program uses
- the program's hierarchy of Components
- how events propagate through the hierarchy
- how drawing occurs
The program converts distance measurements between metric and U.S. units. Here is its source code. Below is the program. If your browser is Java-compatible, you'll see the program running as an applet. Otherwise, you'll see a picture of the program running as an application.
Classes in the Example Program
The example program defines three classes and creates instances of several classes that we provide. It defines an Applet subclass so that it can run as an applet. It creates Components to provide basic controls so that the user can interact with it. Using Containers and LayoutManagers, it groups the Components.The Component Hierarchy
The Components in the example program are arranged in a hierarchy, with Containers defining the structure of the hierarchy.Event Handling
User actions result in events, which are passed up the Component hierarchy until an object responds to the event.Drawing
Components are drawn from the top of the hierarchy -- the program's window -- down to the non-Container Components.
![]() ![]() ![]() ![]() | Table of Contents |